package contracts.task

import org.springframework.cloud.contract.spec.Contract

Contract.make {
    request {
        method 'GET'
        url value(consumer(regex('/api/diff/tasks/[0-9]+/history')),
                producer('/api/diff/tasks/1/history'))
    }
    response {
        status 200
        headers {
            header('Content-Type', 'application/json;charset=UTF-8')
        }
        body("""
                 [{
                    "topicId":1,
                    "taskId":1,
                    "title":"title",
                    "content":"content",
                    "visible":true,
                    "fromId":1,
                    "operateTime":"2020-01-10",
                    "username":"user",
                    "operation":"UPDATE",
                    "assignments":[
                        {
                            "id":1,
                            "taskId":1,
                            "assignmentId":1,
                            "fromId":1,
                            "title":"title",
                            "type":"BASIC_QUIZ",
                            "visible":true,
                            "operateTime":"2020-02-10",
                            "operatorId":1,
                            "operation":"UPDATE",
                            "quizzesId":"1"
                        }
                    ]
                 }] 
                """
        )
        bodyMatchers {
            jsonPath('$.[*]', byType())
            jsonPath('$.[*].topicId', byRegex(number()))
            jsonPath('$.[*].taskId', byRegex(number()))
            jsonPath('$.[*].title', byRegex("[\\s\\S]+"))
            jsonPath('$.[*].content', byRegex("[\\s\\S]+"))
            jsonPath('$.[*].operateTime', byRegex("[\\s\\S]+"))
            jsonPath('$.[*].username', byRegex("[\\s\\S]+"))
            jsonPath('$.[*].operation', byRegex("[\\s\\S]+"))
            jsonPath('$.[*].fromId', byRegex(number()))
            jsonPath('$.[*].visible', byRegex(nonEmpty()))
        }
    }
}
